package lambdademo;

/**
 * Creared with IntelliJ IDEA.
 * Description:
 * User:yxd
 * Date:2022-03-02
 * Time:15:56
 */
class Demo{
    public void func(){
        System.out.println("func()");
    }
}
public class Test1 {
    public static void main(String[] args) {
        int a = 100;
        //a = 9;//不能修改,否则不能捕获到
        new Demo(){
            @Override
            public void func() {
                System.out.println("内部类,重写方法");
                System.out.println("捕获变量" + a);//捕获变量 要么是常量,要么没有发生修改,否则不能捕获
            }
        }.func();
    }
}
